package exception;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class ExceptionDemo01 {
    public static void main(String[] args) {

        doMethod02("fwqf");
    }
    /**
     *写一个方法用于计算两个整数相除的结果
     */
    static int doMethod01 ( int a, int b){
        try {
            int result = a / b;
            return result;
        } catch (ArithmeticException e) {
            System.out.println("除数不能为0");
            return -1;
        }
    }
    static int doMethod02(String string){
        try {
            int result = Integer.parseInt(string);
            return result;
        } catch (NumberFormatException e) {
            System.out.println(string + "字符串转换为整数失败");
            return -1;
        }
    }
    static void doMethod03(){
        FileInputStream fis = null;
        try {
            //
            fis = new FileInputStream("a.dat");
        }catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println("文件可能不存在");
        }
    }
}
